<template>
  <div class="login-container">
    <div class="logo-content"></div>
    <div class="form-content">
      <div class="title">账号登录</div>
      <div class="form-input">
        <el-form ref="loginForm" rules="loginRules" :model="loginForm">
          <el-form-item label="账号：">
            <el-input v-model="loginForm.userName" placeholder="请输入账号"></el-input>
          </el-form-item>
          <el-form-item label="密码：">
            <el-input v-model="loginForm.password" type="password" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button style="width: 100%;background-color: #FF47AB;border: #FF47AB;" type="primary" @click="handleLogin">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import QRCode from 'qrcodejs2'
import portList from '../../configData/configPort'
import md5 from '@/utils/md5'
import { mapGetters } from 'vuex'
import { sendma, updatapwd, login, getInfo, verification, change1, companyPageList } from '@/api/user'
export default {
  name: 'Login',

  data() {
    const validatePassword4 = (rule, value, callback) => {
      if (value == '') {
        callback(new Error('请输入验证码'))
      } else {
        callback()
      }
    }
    const validatePassword2 = (rule, value, callback) => {
      if (value == '') {
        callback(new Error('请输入新密码'))
      } else if (value.length < 6) {
        callback(new Error('密码不能少于6位'))
      } else {
        callback()
      }
    }
    const validatePassword3 = (rule, value, callback) => {
      if (value == '') {
        callback(new Error('请输入确认密码'))
      } else if (value.length < 6) {
        callback(new Error('密码不能少于6位'))
      } else if (this.ruleForm.newpassword != this.ruleForm.agreepassword) {
        callback(new Error('新密码和确认密码不一致'))
      } else {
        callback()
      }
    }
    const validatephone = (rule, value, callback) => {
      if (value == '') {
        callback(new Error('请输入手机号'))
      } else if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(value)) {
        callback(new Error('手机号格式不正确'))
      } else {
        callback()
      }
    }
    const validateUsername = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入用户名'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error('密码不能少于6位'))
      } else {
        callback()
      }
    }

    return {
      reg: /^[1][3,4,5,7,8,9][0-9]{9}$/,
      loginForm: {
        userName: 'admin',
        password: '123456'
      },
      loginRules: {
        userName: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
    }
  },
  watch: {
    
  },
  created() {
  },
  mounted() {
    
  },
  destroyed() {
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('user/login', this.loginForm).then((res) => {
            this.$router.push({ path: '/', query: this.otherQuery })
            this.loading = false
          })
          .catch(() => {
            this.loading = false
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  display: flex;
  overflow: hidden;
  min-height: 100%;
  height: 100%;
  background-color: #EAECF0;

  .logo-content {
    width: 1300px;
    background: url('../../images/logo.png') center/cover no-repeat;
  }

  .form-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 85px;
    box-sizing: border-box;

    .title {
      margin-bottom: 50px;
      font-weight: bold;
      font-size: 24px;
      color: #222222;
    }
  }
}
</style>
